﻿using UnityEngine;
using System;

public class ResHelper
{
    /// <summary>
    /// Load into memory.
    /// </summary>
    /// <param name="path"></param>
    /// <param name="_action"></param>
    public static void LoadIntoM(string path, Action<UnityEngine.Object> _action)
    {
        //TODO... 
        UnityEngine.Object obj = Resources.Load(path, typeof(UnityEngine.Object));
        if (obj == null)
        {
            Debugger.LogWarning(string.Format("object {0} does not exists!!!!", path));
            return;
        }

        if (_action != null) _action(obj);
    }

    /// <summary>
    /// 加载本地资源
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
	public static void LoadLocalRes(string path, Action<UnityEngine.Object> _action)
    {
        LoadIntoM(path, (prefab) =>
        {
            UnityEngine.Object obj = GameObject.Instantiate(prefab);
            if (_action != null) _action(obj);
        });
    }
}
